<div class="page-content">
    <!-- BEGIN PAGE HEADER-->
	<div class="row">
		<div class="col-md-12">
			<!-- BEGIN PAGE TITLE & BREADCRUMB-->
			<h3 class="page-title">
			<?php trans('category_edit_page') ?>
			</h3>
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<i class="fa fa-home"></i>
					<a href="<?php echo admin_url() ?>">
						<?php trans('home_admin') ?>
					</a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="<?php echo admin_url() ?>category">
						<?php trans('category_page') ?>
					</a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="javascript:void(0)">
						<?php trans('category_edit_page') ?>
					</a>
				</li>
			</ul>
			<!-- END PAGE TITLE & BREADCRUMB-->
		</div>
	</div>
	<!-- END PAGE HEADER-->
	<!-- BEGIN PAGE CONTENT-->
    <div class="row">
        <div class="col-md-12">
        	<!-- BEGIN VALIDATION STATES-->
        	<div class="portlet box blue">
        		<div class="portlet-title">
        			<div class="caption">
        				<i class="fa fa-reorder"></i><?php trans('managed_table') ?>
        			</div>
        		</div>
        		<div class="portlet-body form">
        			<!-- BEGIN FORM-->
        			<form action="" id="form_article" class="form-horizontal" method="post">
        				<div class="form-body">
        					<div class="alert alert-danger display-hide">
        						<button class="close" data-close="alert"></button>
        						You have some form errors. Please check below.
        					</div>
        					<div class="alert alert-success display-hide">
        						<button class="close" data-close="alert"></button>
        						Your form validation is successful!
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3"><?php trans('category_parent') ?>
        						<span class="required">
        							 *
        						</span>
        						</label>
        						<div class="col-md-4">
        							<select class="form-control" name="category">
        								<option value="0"><?php trans('main_category') ?></option>
                                        <?php
                                            foreach($list_category as $cate)
                                            {
                                                $level = $cate['level'];
                                                $span = "";
                                                for($l = 0; $l < $level; $l++)
                                                {
                                                    $span .= "-- ";
                                                }
                                                $title_category = $level == 0 ? "<span class='title_parent'>". $span . $cate['title'] ."<span>" : $span . $cate['title'];
                                                
                                                $selected = $cate['category_id'] == $category['category_id'] ? "selected='selected'" : "";
                                        ?>
        								<option <?php echo $selected ?> value="<?php echo $cate['category_id'] ?>"><?php echo $title_category ?></option>
                                        <?php
                                            }
                                        ?>
        							</select>
        						</div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3"><?php trans('status') ?>
                                    <span class="required">*</span>
        						</label>
                                <div class="col-md-4">
                                    <?php
                                        $status = $category['status'];
                                        $selected_enable = $status == 1 ? "selected='selected'" : "";
                                        $selected_disable = $status == 0 ? "selected='selected'" : "";
                                    ?>
        							<select class="form-control" name="status">
        								<option <?php echo $selected_enable ?> value="1"><?php trans('enable') ?></option>
                                        <option <?php echo $selected_disable ?> value="0"><?php trans('disable') ?></option>
        							</select>
        						</div>
        					</div>
                            
        					<div class="form-group">
        						<label class="control-label col-md-3"><?php trans('sort_order') ?>
  						            <span class="required">*</span>
        						</label>
        						<div class="col-md-4">
        							<input type="text" name="sort_order" data-required="1" class="form-control" value="<?php echo $category['sort_order'] ?>"/>
        						</div>
        					</div>
        					<div class="form-group">
        						<label class="control-label col-md-3"><?php trans('other') ?>&nbsp;&nbsp;</label>
        						<div class="col-md-4">
        							<input name="other" type="text" class="form-control" value="<?php echo $category['other'] ?>"/>
        						</div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3"><?php trans('image') ?>&nbsp;&nbsp;</label>
        						<div class="col-md-4">
                                    <div class="btn-group btn-group-xs btn-group-solid">
                                    <?php
                                        $main_image = "public/upload/images/no-image.jpg";
                                        if(!empty($category_image))
                                        {
                                            $main_image = $category_image['main_image']['url'];
                                            if(!file_exists($main_image))
                                                $main_image = "public/upload/images/no-image.jpg";
                                        }
                                    ?>
                                        <img id="main_image" class="show_image_browse" src="<?php echo $main_image ?>" />
                                        <input class="main_image" type="hidden" name="main_image" value="<?php echo $main_image ?>" />
                                        <div class="clear"></div>
                                        <button class="btn blue fileBrowse" data-target="main_image" type="button"><?php trans('browse_file') ?></button>
										<button class="btn red fileDelete" data-target="main_image" type="button"><?php trans('delete_file') ?></button>
								    </div>
                                </div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3"><?php trans('image_other') ?>&nbsp;&nbsp;</label>
        						<div class="col-md-8 other_image">
                                    <?php
                                        if(!empty($category_image['other_image']))
                                        {
                                            $other_image = $category_image['other_image'];
                                            $i = 1;
                                            foreach($other_image as $image)
                                            {
                                    ?>
                                                
                                                <div class="btn-group btn-group-xs btn-group-solid">
                                                    <img src="<?php echo $image['url'] ?>" class="show_image_browse" id="other_image_<?php echo $i ?>"/>
                                                    <input type="text" title="Sort order" name="order_image[]" value="<?php echo $image['sort_order'] ?>" class="order_other_image"/>
                                                    <input type="hidden" value="<?php echo $image['url'] ?>" name="other_image[]" class="other_image_<?php echo $i ?>"/>
                                                    <div class="clear"></div>
                                                    <button type="button" data-target="other_image_<?php echo $i ?>" class="btn blue fileBrowse">Browse File</button>
                                                    <button type="button" data-target="other_image_<?php echo $i ?>" class="btn red fileDelete">Delete File</button>
                                                </div>
                                    <?php
                                            $i++;
                                            }
                                        }
                                    ?>
                                    
                                    
                                    
                                    
                                    <div class="btn_add_image">
                                        <img src="<?php echo base_url() ?>public/backend/assets/img/add-image.png" alt="<?php trans('add_image') ?>" />
                                    </div>
                                    <!--
                                    <div class="btn-group btn-group-xs btn-group-solid">
                                        <img src="public/upload/images/no-image.jpg" class="show_image_browse" id="other_image_6"/>
                                        <input type="text" title="Sort order" name="order_image[]" value="" class="order_other_image"/>
                                        <input type="hidden" value="public/upload/images/no-image.jpg" name="other_image[]" class="other_image_6"/>
                                        <div class="clear"></div>
                                        <button type="button" data-target="other_image_6" class="btn blue fileBrowse">Browse File</button>
                                        <button type="button" data-target="other_image_6" class="btn red fileDelete">Delete File</button>
                                    </div>
                                    -->
                                </div>
        					</div>
                            <div class="form-group">
        						<label class="control-label col-md-3"></label>
        						<div class="col-md-9">
                        			<div class="tabbable tabbable-custom">
                        				<ul class="nav nav-tabs">
                                        <?php
                                            $i = 0;
                                            foreach($language as $lang)
                                            {
                                                $active = $i++ == 0 ? " class='active' " : "";
                                        ?>
                        					<li <?php echo $active ?>>
                        						<a data-toggle="tab" href="#tab_<?php echo $lang['lang_code'] ?>">
                        							 <img src="<?php echo base_url() ?>public/backend/assets/img/flags/<?php echo $lang['image'] ?>" />
                                                     <?php echo $lang['title'] ?>
                        						</a>
                        					</li>
                                        <?php
                                            }
                                        ?>
                        				</ul>
                        				<div class="tab-content">
                                        <?php
                                            $i = 0;
                                            foreach($language as $lang)
                                            {
                                                 $active = $i++ == 0 ? " active " : "";
                                                 $lang_code = $lang['lang_code'];
                                        ?>
                                            <div id="tab_<?php echo $lang_code ?>" class="tab-pane <?php echo $active ?>">
                                                <div class="form-group">
                            						<label class="control-label mgl15"><?php trans('title') ?>
                                                        <span class="required">*</span>
                            						</label>
                            						<div class="col-md-12">
                            							<input value="<?php echo @$category_desc[$lang_code]['title'] ?>" type="text" name="title_<?php echo $lang_code ?>" data-required="1" class="form-control"/>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15"><?php trans('link') ?>
                                                        <span class="required">*</span>
                            						</label>
                            						<div class="col-md-12">
                            							<input value="<?php echo @$link[$lang_code]['link'] ?>" type="text" name="link_<?php echo $lang_code ?>" data-required="1" class="form-control"/>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        <?php trans('short_description') ?>
                            						</label>
                            						<div class="col-md-12">
                            							<textarea id="description_<?php echo $lang_code ?>" class="form-control" name="description_<?php echo $lang_code ?>" rows="6"><?php echo @$category_desc[$lang_code]['description'] ?></textarea>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        <?php trans('long_description') ?>
                            						</label>
                            						<div class="col-md-12">
                            							<textarea class="ckeditor form-control" name="long_description_<?php echo $lang_code ?>" rows="6"><?php echo @$category_desc[$lang_code]['long_description'] ?></textarea>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                            						<label class="control-label mgl15">
                                                        <?php trans('meta_title') ?>
                                                    </label>
                            						<div class="col-md-12">
                            							<input value="<?php echo @$category_desc[$lang_code]['meta_title'] ?>" type="text" name="meta_title_<?php echo $lang_code ?>" class="form-control"/>
                            						</div>
                            					</div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                                                    <label class="control-label mgl15">
                                                        <?php trans('meta_description') ?>
                            						</label>
                            						<div class="col-md-12">
                            							<textarea name="meta_description_<?php echo $lang_code ?>" class="form-control"><?php echo @$category_desc[$lang_code]['meta_description'] ?></textarea>
                            						</div>
                                                </div>
                                                <!--END_INPUT_FORM-->
                                                <div class="form-group">
                                                    <label class="control-label mgl15">
                                                        <?php trans('meta_keywords') ?>
                            						</label>
                            						<div class="col-md-12">
                            							<textarea name="meta_keywords_<?php echo $lang_code ?>" class="form-control"><?php echo @$category_desc[$lang_code]['meta_keywords'] ?></textarea>
                            						</div>
                                                </div>
                                                <!--END_INPUT_FORM-->
                                                <div class="clearfix"></div>
                        					</div>
                        					<!--end tab-pane-->
                                            <?php
                                                }
                                            ?>
                                            <div class="clearfix"></div>
                        				</div>
                                        
                        			</div>
                        		</div>
        					</div>
                            <div class="clearfix"></div>
        				</div>
        				<div class="form-actions fluid">
        					<div class="col-md-offset-3 col-md-9">
                                <button type="submit" class="btn blue" name="btn_submit" value="ok"><?php trans('submit') ?></button>
        						<button type="button" class="btn default"><?php trans('cancel') ?></button>
        					</div>
        				</div>
                        
        			</form>
        			<!-- END FORM-->
        		</div>
        		<!-- END VALIDATION STATES-->
        	</div>
        </div>
    </div>
</div>
<!-- END CONTENT -->
<script type="text/javascript" src="<?php echo public_url() ?>backend/assets/plugins/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?php echo public_url() ?>backend/assets/plugins/ckfinder/ckfinder.js"></script>
<script>
<?php
    foreach($language as $lang)
    {
        $lang_code = $lang['lang_code'];
?>
    var description_<?php echo $lang_code ?> = CKEDITOR.replace('description_<?php echo $lang_code ?>');
    CKFinder.setupCKEditor( description_<?php echo $lang_code ?>, '../public/backend/assets/plugins/ckfinder/' );
    var long_description_<?php echo $lang_code ?> = CKEDITOR.replace('long_description_<?php echo $lang_code ?>');
    CKFinder.setupCKEditor( long_description_<?php echo $lang_code ?>, '../public/backend/assets/plugins/ckfinder/' );
<?php
    }
?>
</script>
<script>
    $(document).ready(function() {
        $(".fileBrowse").live('click',function(){
            var finder = new CKFinder();
            var target = $(this).attr('data-target');
            finder.selectActionFunction = function (fileUrl, data) {
                $('#'+target).attr('src',fileUrl);
                $('.'+target).val(fileUrl);
            }
            finder.popup();
        });
        $(".fileDelete").live('click',function(){
            var target = $(this).attr('data-target');
                $('#'+target).attr('src','public/upload/images/no-image.jpg');
                $('.'+target).val('public/upload/images/no-image.jpg');
        });
    });
</script>